package com.multi.thread.chapter01;

public class StopThrowLockThread extends Thread {
	
	private SynchronizedObject obj;
	
	public StopThrowLockThread(SynchronizedObject obj) {
		this.obj = obj;
	}

	@Override
	public void run() {
		obj.printString("b", "bb");
	}

	public static void main(String[] args) throws InterruptedException {
		SynchronizedObject object = new SynchronizedObject();
		StopThrowLockThread thread = new StopThrowLockThread(object);
		thread.start();
		Thread.sleep(100);
		thread.stop();
		System.err.println(object.getUsername() + ", " + object.getPassword());
	}
}

class SynchronizedObject {
	private String username = "a";
	private String password = "aa";

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	synchronized public void printString(String username, String password) {
		try {
			this.username = username;
			Thread.sleep(1000);
			this.password = password;
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
